﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp.View.SystemInformation
{
    /// <summary>
    /// WD_PrintStaff.xaml 的交互逻辑
    /// </summary>
    
    public partial class WD_PrintStaff : Window
    {
        public DataRowView DRV;
        BLL.UCStaffInformation.UC_StaffInformationClient myStaff = new BLL.UCStaffInformation.UC_StaffInformationClient();
        public WD_PrintStaff(DataRowView dv)
        {
            InitializeComponent();
            DRV = dv;
        }
        /// <summary>
        /// 页面加载时（这里回填数据）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            #region 获取页面传递过来的数据（回填）
            txt_StaffName.Text = DRV.Row["staffName"].ToString().Trim();
            txt_Branch.Text = DRV.Row["Branch"].ToString().Trim();
            txt_Type.Text = DRV.Row["EmployeeType"].ToString().Trim();
            txt_StaffNumber.Text = DRV.Row["staffNumber"].ToString().Trim();
            #endregion
            #region 显示图片
            string strOldLuJing = DRV.Row["staffPicture"].ToString();
            //根据图片名获取图片文件
            string myPictureByte = myStaff.SelectPhoro(strOldLuJing);
            if (myPictureByte != null)
            {
                try
                {
                    BitmapImage bi = new BitmapImage();
                    bi.BeginInit();
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.UriSource = new Uri(myPictureByte);
                    bi.EndInit();
                    //获取内存图片
                    imgb_Photo.ImageSource = bi;
                }
                catch (Exception)
                {
                    imgb_Photo.ImageSource = null;
                }
            }
            #endregion


        }
        /// <summary>
        /// 打印按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Print_Click(object sender, RoutedEventArgs e)
        {
            //实例化打印对话框
            PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
                //打印visual（非文本）对象(打印区域,要打印的作业的说明)
                dialog.PrintVisual(printArea, "打印");
            }
        }
    }
}
